package org.linlinjava.litemall.admin.service;

import org.linlinjava.litemall.db.domain.LitemallUser;
import org.linlinjava.litemall.db.domain.PiccNurse;
import org.linlinjava.litemall.db.domain.PiccPatient;
import org.linlinjava.litemall.db.service.LitemallUserService;
import org.linlinjava.litemall.db.service.PiccNurseService;
import org.linlinjava.litemall.db.service.PiccPatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminPiccPatientService {
    @Autowired
    PiccPatientService piccPatientService;

    @Autowired
    PiccNurseService piccNurseService;

    @Autowired
    LitemallUserService litemallUserService;

    public PiccPatient add(PiccPatient info){
        if (info.getId()==null) {
            String jobNum = info.getJobnum();
            PiccNurse nurse = piccNurseService.getDetailByJobNum(jobNum);
            info.setNurseId(nurse.getId());
            piccPatientService.add(info);

            LitemallUser user = litemallUserService.findById(info.getUserId());
            user.setRole("patient");

            return info;
        }else if (info.getId()>0){
            piccPatientService.update(info);
            return info;
        }else
            return new PiccPatient();
    }
}
